package com.neuedu.it.newidea.web;

import com.neuedu.it.newidea.web.dto.RespEntity;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class AISearchController {

    @Autowired
    @Qualifier("chatClientSearch")
    private ChatClient chatClientSearch;

    //MVC拦截中放行，我们对可以查询的敏感信息过滤，故设计为不用登录也可以查询
    @PostMapping("/ai/search")
    public RespEntity aiSearch(@RequestParam String ask) {
        String answer = chatClientSearch.prompt()
                .user(ask)
                .call()
                .content();
        return new RespEntity("2000", "AI搜索成功", answer);
    }
}